var fansList

$(document).ready(function(){
    fansList = new Vue({
        el: "#fansList",
        data: {
            fansList: '',
            total:{},
            click_total:'',
        },
        created: function(){
            var that = this
            // getDataTotal(that.fansList,'','')
            getTotalFansList({},function(res){
                $("#pages03").html('')
                getTotalPageNum({
                    el: "#pages03",
                    limit: res.result.per_page, 
                    count: res.result.total, //数据总数,
                    clickPage: function(obj,first){
                        $("#loadOn").fadeIn()
                        if(first){
                            that.fansList = res.result.data
                            $("#loadOn").fadeOut()
                            return
                        }
                        getTotalFansList({page:obj.index,},function(reres){
                            
                            that.fansList = reres.result.data
                            $("#loadOn").fadeOut()
                            $('.layui-body').animate({ scrollTop: 0 }, 400);
                        })
                    }
                })
                console.log(res)
                that.total = res.count;
                that.click_total = res.click_count;
            })
            console.log(that.fansList)
        },
        methods:{
            getTime: function(){
                $("#loadOn").fadeIn()
                var that = this
                var start = (new Date($("#chioceTime").val().substr(0,19))).getTime()/1000;
                var stop = (new Date($("#chioceTime").val().substr(22,19))).getTime()/1000;
                that.fansList = ''
                getTotalFansList({start_time:start,end_time:stop},function(res){
                    $("#pages03").html('')

                    getTotalPageNum({
                        el: "#pages03",
                        limit: res.result.per_page, 
                        count: res.result.total, //数据总数,
                        clickPage: function(obj,first){
                            $("#loadOn").fadeIn()
                            if(first){
                                that.fansList = res.result.data
                                $("#loadOn").fadeOut()
                                return
                            }
                            getTotalFansList({start_time:start,end_time:stop,page:obj.index,},function(reres){
                                that.fansList = reres.result.data
                                $("#loadOn").fadeOut()
                                $('.layui-body').animate({ scrollTop: 0 }, 400);
                            })
                            
                        }
                    })
                    console.log(res)
                    that.total = res.count;
                })
                
            },
            setImg: function(res){
                console.log(res)
                setCookie('img', res.head_pic)
                setCookie('openId',res.openid)
                setCookie('nikeName',res.nickname)
                window.location.href = '/admin/fans/chat.html'
            },
            footprint : function(item){
                var that = this;

                getFootPrint(item.openid,function(res){
                    var str = '';
                    str += '<div style="margin:10px;font-size:14px;color:#666;">';
                    res.forEach(function(val){
                        var time = changeTime(val.action_time);
                        if(val.action == 1){
                            var event = '<span style="background-color:#66CD00;color:#fff;border-radius:4px;padding:0 4px;">关注</span>';
                        }else if(val.action == 2){
                            var event = '<span style="background-color:red;color:#fff;border-radius:4px;padding:0 4px;">取消关注</span>';
                        }
                        str += '<div style="line-height:25px;">用户：'+item.nickname+'在 ' + time+ ' ' + event+ ' ' + '公众号</div>';
                    });
                    str += '</div>';
                    console.log(str);
                    layer.open({
                        type: 1,
                        content: str, //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                        area : ['400px','700px'],
                    });
                });
            }
        } 
    })
})